package com.codeczx.recyclerviewdemo.progress;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.codeczx.recyclerviewdemo.R;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

public class ProgressActivity extends AppCompatActivity {

    private static final String TAG = "codeczx";
    private RecyclerView rv;
    private RVAdapter adapter;
    private List<String> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress);
        rv = (RecyclerView) findViewById(R.id.rv);

        rv.setLayoutManager(new LinearLayoutManager(this));

        list = new ArrayList<>();
        for(int i = 0;i<10;i++){
            list.add(i+"");
        }
        adapter = new RVAdapter(list);
        rv.setAdapter(adapter);

        new Thread(new Runnable() {
            @Override
            public void run() {
                int i = 0;
                while (i<100){
                    EventBus.getDefault().post(new ProgressEvent(i,1));
                    EventBus.getDefault().post(new ProgressEvent(i/2,2));
                    Log.i(TAG,"i:"+i);
                    i++;
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        }).start();
    }
}
